package com.wh.hotel.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.wh.hotel.dao.HotelRoomTypeCalendarDao;
import com.wh.hotel.enums.strategy.PriceStrategyTypeEnum;
import com.wh.hotel.po.SuitHotelRoomPo;
import com.wh.hotel.service.HotelPriceStrategyService;
import com.wh.hotel.service.HotelRoomTypeCalendarService;
import com.wh.hotel.util.DateWhUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author luweije
 */
@Slf4j
@Service
public class HotelRoomTypeCalendarServiceImpl implements HotelRoomTypeCalendarService {

    private static final int DEFAULT_SELL_DAYS = 10;

    @Resource
    private HotelPriceStrategyService hotelPriceStrategyService;

    @Resource
    private HotelRoomTypeCalendarDao hotelRoomTypeCalendarDao;

    @Override
    public void roomTypeBasePriceChange(Long hotelId, Long roomTypeId) {
        SuitHotelRoomPo suitHotelRoomPo = new SuitHotelRoomPo();
        suitHotelRoomPo.setHotelId(hotelId);
        suitHotelRoomPo.setRoomTypeIdList(Lists.newArrayList(roomTypeId));
        Date today = DateWhUtil.dayStart(new Date());
        List<Date> sellDateList = hotelRoomTypeCalendarDao.selectDistinctSellDate(roomTypeId, today);
        if (CollUtil.isEmpty(sellDateList)) {
            sellDateList = DateWhUtil.createDateByDay(today, DEFAULT_SELL_DAYS);
        }
        hotelPriceStrategyService.hitAndUpdatePriceStrategy(suitHotelRoomPo, sellDateList, PriceStrategyTypeEnum.BASE_PRICE);
    }
}
